(function ($) {
    $.upgrade = {
        config: {},
        init: function (d) {
            $.extend(this.config, d, true);
        },
        btnUpgrade: function () {
            var _self = this;
            $(".shengji").bind("click", function () {
                var id = $(this).attr("data-id");
                var d = dialog({
                    title: '升级账户级别（注：此页面只用于账号级别升级）',
                    content: '选择升级方式：<select id="nametype" name="nametype"><option value="1">充值预付款升级</option><option value="2">购买升级</option><select/>',
                    ok: function () {
                        var type = $("#nametype").val();
                        $.post(_self.config.upgradeurl, {"id": id, "nametype": type, upgrade: 1}, function (data) {
                            if (data.status === true) {
                                window.location.href = data.url;
                            } else {
                                alert(data.message);
                            }
                        }, "json");
                    },
                    okValue: "确认",
                    cancelValue: '取消',
                    cancel: function () { }
                });
                d.showModal();
            });
        },
        /*
         * 提现返利金额
         */
        withdrawal: function () {
            var _self = this;
            $(".withdrawal").bind("click", function () {
                var d = dialog({
                    title: '提现返利金额',
                    content: '确定要将返利金额提现出来吗？',
                    ok: function () {
                        $.post(_self.config.withdrawalurl, {}, function (data) {
                            if (data.status === true) {
                                window.location.href = data.url;
                            } else {
                                alert(data.msg);
                            }
                        }, "json");
                    },
                    okValue: "确认",
                    cancelValue: '取消',
                    cancel: function () { }
                });
                d.showModal();
            });
        },
        /*
         * 返利金额充值到账号
         */
        rebateup: function () {
            var _self = this;
            $(".rebateup").bind("click", function () {
                var d = dialog({
                    title: '将返利金额充值进账户',
                    content: '确定要将返利金额充值进账户吗？',
                    ok: function () {
                        $.post(_self.config.rebateupurl, {}, function (data) {
                            if (data.status === true) {
                                window.location.reload();
                            } else {
                                alert(data.msg);
                            }
                        }, "json");
                    },
                    okValue: "确认",
                    cancelValue: '取消',
                    cancel: function () { }
                });
                d.showModal();
            });
        }
    };
})(jQuery);